package logic

import (
	"api/pkg"
	"context"
	"github.com/google/uuid"
	"order_srv/order"

	"api/internal/svc"
	"api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type AddOrderLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewAddOrderLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AddOrderLogic {
	return &AddOrderLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *AddOrderLogic) AddOrder(req *types.AddOrderRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line
	l.svcCtx.OrderSrv.AddOrder(l.ctx, &order.AddOrderRequest{Status: int64(req.Status)})
	if req.Status < req.Status {
		return &types.Response{
			Code: -1,
			Msg:  "库存不足",
			Data: nil,
		}, nil
	}

	orderSn := uuid.NewString()
	uil := pkg.Alipay(orderSn, "13")

	return &types.Response{
		Code: 1,
		Msg:  "支付成功",
		Data: map[string]interface{}{
			"Uil": uil,
		},
	}, nil
}
